/* 

This do file produces the main results tables and figures in the main body of
the article: Wood, T, Hoy, C & Pryke, J "The effect of geostrategic competition 
on public attitudes to aid", Journal of Experimental Political Science.

This do file is focused on the AUSTRALIAN DATA.

Please email all questions to: terence.wood@anu.edu.au/terencewoodnz@gmail.com

This file does the following:

1. Preliminaries
2. Loops through each of the dependent variables of interest running, (a) a
   bivariate regression in which treatment group is the independent variable 
   and the control group is the comparator & (b) an identical regression testing
   the difference between the measured and forceful treatment groups.
3. Exports the outputs of the regressions for all dependent variables of interest
   as a single table in an rtf file. (Table 1 in paper.)
4. Produces a margins plot to demonstrate magnitude of treatment effects on aid 
   purpose (Figure 1 in paper.) 
	
Do file coded in Stata version 14. 

You need to install the estout package before running this code:
http://repec.sowi.unibe.ch/stata/estout/
	
*/


********************************************************************************
********************************Preliminaries***********************************
********************************************************************************

set more off

cd "ENTER YOUR WORKING DIRECTORY HERE"

use "1 Australia data JEPS FINAL", clear

********************************************************************************
*********************OLS regression based estimates of effect*******************
********************************************************************************

estimates clear

//loop through each independent variable of interest
foreach question in too_much_aid more_to_pac favour_aus {
	
	//determine string to use in model's title based on 
	//which dependent variable is currently in loop
	if "`question'" == "too_much_aid" {
		local qtitle "Too much aid"
		}
		else if "`question'" == "more_to_pac" {
		local qtitle "More to Pacific"
		}
		else if "`question'" == "favour_aus" {
		local qtitle "Help Australia"
		}

	if "`question'" == "too_much_aid" {
		local mname tma
		}
		else if "`question'" == "more_to_pac" {
		local mname pf
		}
		else if "`question'" == "favour_aus" {
		local mname ap
		}

		
	//Run regression comparing treatments with control
	qui reg `question' i.treatment_group 
	estimates store `mname', title("`qtitle'")
	
	//Run regression identifying difference in treatments
	qui reg `question' ib2.treatment_group 
	estimates store `mname'_b, title("Diff in treats")

}

//produce table of results.
esttab tma tma_b pf pf_b ap ap_b using results.rtf, append b(2) se(2) ///
label mtitle nobase starlevel(* 0.1 ** 0.05 *** 0.01) ///
drop(1.treatment_group) nogaps nonotes coeflabels(_cons "Control group mean") ///
addnote("Standard errors in parentheses; * p<0.1, ** p<0.05, *** p<0.01")

macro drop _all 
estimates clear

********************************************************************************
*****************************Margins plot***************************************
********************************************************************************

qui reg favour_aus i.treatment_group

qui margins treatment_group
	
marginsplot, recast(bar) graphregion(color(white)) title("") xtitle("") ///
	ytitle("Share favour national interest") ///
	plotopts(fcolor(gs10) lcolor(gs8)) ciopts(lcolor(gs6)) ///

estimates clear
